package com.first.orange.controller.person;

import com.first.orange.beans.Orders;
import com.first.orange.beans.Product;
import com.first.orange.beans.UserInformation;
import com.first.orange.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Map;

/**
 * Created on 2021/7/5.
 * <p>
 * Author : Lcywings
 * <p>
 * Description :
 */
@Controller
public class PersonCenterController {

    @Autowired
    PersonService personService;

    //用户id假数据
    private Integer userId = 1;

    /**
     * @author : Lcywings
     * @date : 2021/7/5 12:27
     * @acl : true
     * @description : 个人中心首页，获取个人资产数据&订单&收藏&足迹
     */
    @RequestMapping(value = "/personCenter", method = RequestMethod.GET)
    public String getPersonalAssets(Map<String, Object> map) {

        //个人资产
        //获取用户信息
        UserInformation userInformation = (UserInformation) personService.getPersonalAssets(userId).get("userInformation");
        // 获取账户余额
        map.put("accountBalance", userInformation.getAccountBalance());
        // 获取账户总积分
        map.put("totalPoints", userInformation.getTotalPoints());
        // 获取账户昵称
        map.put("nickName", userInformation.getNickName());
        // 获取账户优惠券数量
        map.put("couponTotal", personService.getPersonalAssets(userId).get("couponTotal"));


        //我的订单
        //获取订单详情
        Orders orders = personService.getOrders(userId);
        Product product = personService.getProduct(orders.getShopId());
        map.put("orders",orders);
        map.put("product",product);

        return "person/index";
    }
}
